package praktikumid.p03_e;

/**
 * Kolmas praks.
 * @author ago
 *
 */
public class Kolmas {
	/**
	 * main.
	 * @param args
	 */
	public static void main(String[] args) {
		String word = readWord(args);
		if (word == null) {
			System.out.println("Sona sisestamata");			
		} else {
			System.out.println("Saime sona: " + word);
		}
		
		try {
			String word2 = readWord2(args);
			System.out.println("Saime sona: " + word2);
		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("Sona sisestamata");
			System.exit(0);
		}
	}
	
	/**
	 * Loeb sona kasurea argumentidest.
	 * @param args
	 * @return Sona
	 */
	public static String readWord(String[] args) {
		/*if (args.length < 1) {
			return null;
		}*/
		String word;
		try {
			word = args[0];
			// kood
			// viga
			// kood ei kaivitu
			return word;
		} catch (ArrayIndexOutOfBoundsException e) {
			// kood
			//System.out.println(e.getMessage());
		}
		return null;
	}
	
	/**
	 * @param args argumentide array
	 * @return string
	 * @throws ArrayIndexOutOfBoundsException
	 */
	public static String readWord2(String[] args) 
			throws ArrayIndexOutOfBoundsException {
		return args[0];
	}
}
